package com.qiche.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.qiche.aspect.Result;
import com.qiche.config.YmlConfig;
import com.qiche.model.Insurance;
import com.qiche.service.InsuranceService;
import com.qiche.util.AliyunSmsUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LB
 *
 * @date 2018年7月17日
 */
@RestController
@RequestMapping("/insurance")
public class InsuranceController {
	@Autowired
	public InsuranceService insuranceService;
	
	@Autowired
    private YmlConfig ymlConfig;
	 /**
     * 保险报价
     *
     * @param evaluation
     * @return
     */
    @PostMapping("/submit")
    public Result<?> submit( Insurance insurance)throws Exception {
    	if(StringUtils.isBlank(insurance.getPhone())||StringUtils.isBlank(insurance.getPlateNumber())){
    		return Result.createByErrorMessage("请填完整信息");
    	}
        int saveCount = insuranceService.save(insurance);
        if (saveCount > 0) {
        	//发送短信
        	AliyunSmsUtils.sendSmsInsurance(insurance.getPlateNumber(), insurance.getPhone(), ymlConfig.getManagerPhone());
            return Result.createBySuccessMessage("留言成功");
        }
        return Result.createByErrorMessage("保险报价");

    }
}
